package com.cskaoyan.controller;

import com.cskaoyan.bean.MarketCategory;
import com.cskaoyan.bean.day3.CategoryRespVo;
import com.cskaoyan.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author stone
 * @date 2022/09/08 15:00
 */
@RestController //@Controller + @ResponseBody
// @Controller 把这个组件注册为Controller组件
// @ResponseBody 将响应的结果转换为Json字符串
@RequestMapping("admin/category") //窄化请求
public class AdminCategoryController {

    //Controller层一定使用的是Service层的方法
    @Autowired
    CategoryService categoryService; //获得对象是为了使用里面的方法

    //@RequestMapping("list")//admin/category/list → method → HandlerMethod
    //@RequestMapping(value = "list",method = RequestMethod.GET)
    @GetMapping("list")
    public CategoryRespVo list() {//Handler
        CategoryRespVo returnValue = categoryService.list();
        return returnValue;// → @ResponseBody或@RestController → Json字符串
    }

    @PostMapping("update")
    public Object update(@RequestBody MarketCategory marketCategory) {
        categoryService.modify(marketCategory);
        return null;
    }
}
